package com.qj.travel.service.impl;

import com.qj.travel.db.dao.VoteRecordDao;
import com.qj.travel.db.model.VoteRecordModel;
import com.qj.travel.service.VoteRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Admin on 2016/10/17.
 */
@Service
public class VoteRecordServiceImpl implements VoteRecordService{

    @Autowired
    private VoteRecordDao voteRecordDao;

    public int insertRecord(VoteRecordModel voteRecordModel) {
        return voteRecordDao.insertRecord(voteRecordModel);
    }

    public int selectUserByVideoId(int videoId) {
        return voteRecordDao.selectUserByVideoId(videoId);
    }

    public int selectUserNum(String userId) {
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        String today = new SimpleDateFormat("yyyy年MM月dd日").format(date);
        calendar.setTime(date);
        calendar.add(Calendar.DATE,1);
        date = calendar.getTime();
        String tomorrow = new SimpleDateFormat("yyyy年MM月dd日").format(date);
        return voteRecordDao.selectUserNum(today,tomorrow,userId);
    }

    public int selectIpNum(String voteIp) {
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        String today = new SimpleDateFormat("yyyy年MM月dd日").format(date);
        calendar.setTime(date);
        calendar.add(Calendar.DATE,1);
        date = calendar.getTime();
        String tomorrow = new SimpleDateFormat("yyyy年MM月dd日").format(date);
        return voteRecordDao.selectIpNum(today,tomorrow,voteIp);
    }


}
